<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:inline="javascript">
        $(function () {
            $.get("/plays/clubs",function (data) {
                for (club of data){
                    if (club.cid == [[${cid}]]){
                        $("select").append("<option value='"+club.cid+"' selected>"+club.cname+"</option>")
                    }else{
                        $("select").append("<option value='"+club.cid+"'>"+club.cname+"</option>")
                    }
                }
            },"json")
        })
        function del(pid) {
            var pd = confirm("确实要删除吗？")
            if (pd){
                $.get("/plays/delete","pid="+pid,function (data) {
                    if (data==1){
                        alert("删除成功")
                        window.location.reload();
                    }else {
                        alert("删除失败")
                    }
                })
            }
        }
    </script>
</head>
<body>

<div style="width: 800px;margin: 0px auto">
    <h1 style="text-align: center">美国职业篮球联盟（NBA）球员信息</h1>
    <form th:action="@{/plays}" method="get">
        球员姓名：<input type="text" name="pname" th:value="${pname}">
        所属球队：
        <select name="cid">
            <option value="">--请选择--</option>
        </select>
        <input type="submit" value="查询">
        <a href="/plays/add">
            <input type="button" value="添加">
        </a>
    </form>
    <table width="800px" style="text-align: center">
        <tr style="text-align: center;background-color: gainsboro">
            <td>球员编号</td>
            <td>球员姓名</td>
            <td>出生日期</td>
            <td>球员身高</td>
            <td>球员体重</td>
            <td>球员位置</td>
            <td>所属球队</td>
            <td>相关操作</td>
        </tr>

        <tr th:each="play,R:${playList}"th:style="${R.count%2==0}?'background-color: honeydew':'background-color：write'">
            <td th:text="${play.pid}">pid</td>
            <td th:text="${play.pname}">pname</td>
            <td th:text="${#dates.format(play.birthday,'yyyy-MM-dd')}" >birthday</td>
            <td th:text="${play.height}">height</td>
            <td th:text="${play.weight}">weight</td>
            <td th:text="${play.position}">position</td>
            <td th:text="${play.cname}">cname</td>
            <td>
                <a href="javascript:void(0)" th:onclick="del([[${play.pid}]])">删除</a>
                <a th:href="@{/plays/getUp/{pid}(pid=${play.pid})}">修改</a>
            </td>
        </tr>
    </table>

</div>
</body>
</html>

